package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeachplanApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
/*@RequestMapping("teachplan")*/
public class TeachplanController implements TeachplanApi {

    @Autowired
    private TeachplanService  teachplanService;

    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public TeachplanDTO queryTeachplanById(@PathVariable Long courseId) {

        Long companyId = SecurityUtil.getCompanyId();

        TeachplanDTO dto = teachplanService.queryTeachplanById(courseId, companyId);

        return dto;
    }

    @PostMapping("/teachplan")
    public TeachplanDTO createOrSetTeachPlan(@RequestBody TeachplanVO teachplanVO) {

        Long companyId = SecurityUtil.getCompanyId();

        TeachplanDTO teachplanDTO = TeachplanConvert.INSTANCE.vo2dto(teachplanVO);

        TeachplanDTO teachPlan = teachplanService.createOrSetTeachPlan(teachplanDTO, companyId);

        return teachPlan;
    }

    @DeleteMapping("/teachplan/{teachPlanId}")
    public void delectteachPlant(@PathVariable Long teachPlanId) {

        Long companyId = SecurityUtil.getCompanyId();

        teachplanService.delectteachPlant(teachPlanId,companyId);

    }
}
